//
//  WTPlayCoinView.m
//  WTPlayDemo
//
//  Created by ben on 16/7/14.
//  Copyright © 2016年 ben. All rights reserved.
//

#import "WTPlayCoinView.h"
#import "Masonry.h"
#import "UIColor+WTExtend.h"
#import "NSString+WTShowNumber.h"
#import "UIImage+WTExtend.h"

@interface WTPlayCoinView ()
@property (nonatomic, strong) UILabel*  nameLabel;
@property (nonatomic, strong) UILabel*  valueLabel;
@end

@implementation WTPlayCoinView
- (instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2];

        self.layer.cornerRadius = 12;
        self.layer.masksToBounds = YES;
        
        [self setup];
    }
    return self;
}


#pragma mark -  setup
- (void)setup{
    
    self.nameLabel = ({
        UILabel* label = [[UILabel alloc] init];
        label.textColor = [UIColor themeColor];
        label.font = [UIFont systemFontOfSize:12];
        label.text = @"金币";
        [self addSubview:label];
        label;
    });
    
    self.valueLabel = ({
        UILabel* label = [[UILabel alloc] init];
        label.textColor = [UIColor whiteColor];
        label.font = [UIFont systemFontOfSize:12];
        label.text = [NSString coinCount:@"123785"];
        [self addSubview:label];
        label;
    });

    self.detailButton = ({
        UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage wt_imageWithName:@"wt_left_arrow"] forState:UIControlStateNormal];
        [self addSubview:button];
        button;
    });
    
    [self layout];
    
}

#pragma mark - layout
- (void)layout{
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.mas_leading).offset(22);
        make.centerY.mas_equalTo(self.mas_centerY);
    }];
    
    [self.valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.nameLabel.mas_trailing).offset(12);
        make.centerY.mas_equalTo(self.mas_centerY);
    }];
    
    [self.detailButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.mas_trailing).offset(-15);
        make.width.and.height.mas_equalTo(15);
        make.centerY.mas_equalTo(self.mas_centerY);
    }];
    
}

#pragma mark setter
- (void)setCoinCount:(NSString *)coinCount{
    
    _coinCount = coinCount;
    
    self.valueLabel.text = coinCount;
}
@end
